#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int R = 2e5 + 10;
struct
{
	int son[2], sz;
	unsigned key;
	ll val, res;
} t[R];
#define lc(k) t[k].son[0]
#define rc(k) t[k].son[1]
ll MOD;
int tot, root;
mt19937 rd(2333);
int crt(ll val)
{
	t[++tot] = {.sz = 1, .key = rd(), .val = val, .res = val}; // 别忘了res也要赋值！！！
	return tot;
}
void pushup(int k)
{
	t[k].sz = t[lc(k)].sz + t[rc(k)].sz + 1;
	t[k].res = t[k].val;
	if (lc(k))
	{
		t[k].res = max(t[lc(k)].res, t[k].res);
	}
	if (rc(k))
	{
		t[k].res = max(t[rc(k)].res, t[k].res);
	}
}
void split(int k, int sz, int &x, int &y)
{
	if (!k)
	{
		x = y = 0;
		return;
	}
	if (t[lc(k)].sz + 1 <= sz)
	{
		x = k;
		split(rc(k), sz - (t[lc(k)].sz + 1), rc(x), y);
	}
	else
	{
		y = k;
		split(lc(k), sz, x, lc(y));
	}
	pushup(k);
}
int merge(int x, int y)
{
	if (!x || !y)
	{
		return x | y;
	}
	if (t[x].key < t[y].key)
	{
		rc(x) = merge(rc(x), y);
		pushup(x);
		return x;
	}
	else
	{
		lc(y) = merge(x, lc(y));
		pushup(y);
		return y;
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, lt, rt;
	ll lastans = 0, x;
	char c;
	cin >> n >> MOD;
	while (n--)
	{
		cin >> c >> x;
		if (c == 'Q')
		{
			split(root, tot - x, lt, rt);
			cout << (lastans = t[rt].res) << '\n';
			root = merge(lt, rt);
		}
		else
		{
			root = merge(root, crt((x + lastans) % MOD));
		}
	}
	return 0;
}
